{% extends 'layout/main.html' %}
{% block content_header %}
<div class="row page-titles">
  <div class="col-md-5 col-8 align-self-center">
    <ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="javascript:void(0)">首页</a></li>
      <li class="breadcrumb-item active">栏目列表</li>
    </ol>
  </div>
</div>
{% endblock %}


{% block content %}

<div class="card">
  <div class="card-body">
    <a href="{{ url_for('category.create') }}" class="btn btn-danger p-10 waves-effect waves-light">
      添加栏目
    </a>
    <div class="table-responsive">
      <table class="table table-hover table-bordered m-t-10 text-nowrap">
        <thead>
          <tr>
            <th style="width: 10px">#</th>
            <th>栏目名称</th>
            <th width="150">创建时间</th>
            <th width="150">更新时间</th>
            <th style="width: 40px">操作</th>
          </tr>
        </thead>
        <tbody>
          {% if model %}
          {% for item in model %}
          <tr>
            <td>{{ item.id }}</td>
            <td><span
                style="padding-left: {{ item.level*2 }}0px;">{% if item.level %}├─{% endif %}{{ item.title }}</span>
            </td>
            <td>{{ item.created_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
            <td>{{ item.updated_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
            <td class="text-nowrap">
              <div style="display: flex">
                <a href="{{ url_for('category.update', id=item.id) }}" data-toggle="tooltip" data-original-title="编辑">
                  <i class="fa fa-pencil text-inverse m-r-10"></i> </a>
                <a href="javascript:void(0)" onclick="sa_delete(event)" data-toggle="tooltip" data-original-title="删除">
                  <span class="fa fa-close text-danger" data-id="{{ item.id }}"></span>
                </a>
              </div>
            </td>
          </tr>
          {% endfor %}
          {% endif %}
        </tbody>
      </table>
    </div>
  </div>
</div>
{% endblock %}

{% block scripts %}
{{ super() }}
<script type="text/javascript">
  function sa_delete(e) {
    swal({
      title: "您确定?",
      text: "您确定要删除栏目吗!",
      type: "warning",
      showCancelButton: true,
      confirmButtonColor: "#DD6B55",
      confirmButtonText: "是的, 我确定!",
      cancelButtonText: "取消操作",
      closeOnConfirm: false
    }, function () {
      window.location.href='/category/delete/' + e.srcElement.dataset['id']
    })
  }
</script>
{% endblock scripts %}